/**
 * <p>Title: Cell Class</p>
 * <p>Description: CS 343 Project</p>
 * @author Quintin Stolpe
 * @email quintin.stolpe@my.uwrf.edu
 * @date Dec 3 2012
*/

package maze;

import java.util.Enumeration;
import java.util.Vector;


public class Node
{

	Vector outEdgesVector = new Vector();
	
	public int myX;
	public int myY;
	
	public Edge bestEdge;  // temp holder to be used to find a path
	
	public Node(int x, int y)
	{
		myX = x;
		myY = y;
	}
	
	public void addEdge(Edge anEdge)
	{
		outEdgesVector.add(anEdge);
	}
	
	// returns square of shortest straight line distance between input location and
	// any node within searchDepth range.  
	// Recursive, base case is searchDepth == 0
	public int findPathTo(int x, int y, int searchDepth)
	{
		if (searchDepth == 0)
		{
			return (x-myX)*(x-myX)+(y-myY)*(y-myY);
		}
		
		int bestDepth = -1;
		int tempDepth = 0;
Enumeration<Edge> en2=outEdgesVector.elements();
		
		while (en2.hasMoreElements())
		{
			Edge edge = (Edge)(en2.nextElement());
			if (edge.contains(x,y))
			{
				bestEdge = edge;
				return 0;
			}
			
			tempDepth = edge.endNode.findPathTo(x,y,searchDepth-1);
			
			if (bestDepth < 0 || tempDepth < bestDepth)
			{
				bestDepth = tempDepth;
				bestEdge = edge;
			}	
		}
		return bestDepth;
	}
	public static void main(String[] args)
	{
	}
}
